# coding=utf-8
from django import forms
from com.kjssoft.eagleye.social.consts import EagleyeSocialConsts

__author__ = 'KJS'

class EagleyeBindForm(forms.Form):
    bind_type = forms.ChoiceField(choices=EagleyeSocialConsts.Bind.get_choices())

    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=None,
                 label_suffix=':', empty_permitted=False, user = None):
        super(EagleyeBindForm, self).__init__(data, files, auto_id, prefix, initial, error_class, label_suffix,
            empty_permitted)
        self.user = user

    def clean(self):
        bind_type = self.cleaned_data.get('bind_type')
        #与登陆用户绑定
        if EagleyeSocialConsts.Bind.BIND_TYPE_LOGIN_USER == bind_type:
            if not self.user or not self.user.is_authenticated():
                raise forms.ValidationError('Could not find available login user.')

        return self.cleaned_data



